import { CommonReturnData } from '@/api/model/common';
import type { IdItem, ListParams, PostData, ResultItem, ResultList } from '@/api/model/mockModel';
import { request } from '@/utils/request';

const commonPath = 'mock';

const Api = {
  list: `/${commonPath}/list`,
  create: `/${commonPath}/create`,
  del: `/${commonPath}/del`,
  update: `/${commonPath}/update`,
  info: `/${commonPath}/info`,
};

export function list(params: ListParams) {
  return request.get<CommonReturnData<ResultList>>({
    url: Api.list,
    params,
  });
}

export function create(data: PostData) {
  return request.post<CommonReturnData>({
    url: Api.create,
    data,
  });
}

export function del(data: IdItem) {
  return request.post<CommonReturnData>({
    url: Api.del,
    data,
  });
}

export function update(data: PostData) {
  return request.post<CommonReturnData>({
    url: Api.update,
    data,
  });
}

export function info(params: IdItem) {
  return request.get<CommonReturnData<ResultItem>>({
    url: Api.info,
    params,
  });
}

export default { api: Api, list, create, del, update, info };
